#ifndef __SINGLEMAP_H__
#define __SINGLEMAP_H__

#include <map>
#include <string>
#include <mutex>

using std::string;
using std::map;
using std::mutex;

class MyMap {
public: 
    map<string, int> _myMap;
};

class SingleMap {
public:
    static MyMap *getInstance() {
        if(_mm == nullptr) {
            std::lock_guard<std::mutex> lock(_mutex);
            if(_mm == nullptr) {
                _mm = new MyMap();
                atexit(destory);
            }
        }
        return _mm;
    }

    static void destory() {
        if(_mm) {
            delete _mm;
            _mm = nullptr;
        }
    }

private:
    SingleMap() {}
    ~SingleMap() {}
    SingleMap(const SingleMap &) = delete;
    SingleMap operator=(const SingleMap &) = delete;

private:
    static MyMap *_mm;
    static mutex _mutex;
};


#endif
